package com.superatom.concurrent.basic.daemon;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class DaemonFromFactory implements Runnable{
    public void run() {
        while (true){
            try {
                Thread.sleep(100);
                System.out.println(Thread.currentThread() + " " + this);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) throws InterruptedException {
        // 使用DaemonThreadFactory创建线程
        ExecutorService exec = Executors.newCachedThreadPool(new DaemonThreadFactory());
        for (int i = 0; i < 10; i++){
            exec.execute(new DaemonFromFactory());
        }

        System.out.println("All daemons started");
        Thread.sleep(500);
    }
}
